package com.course.dao;

import com.course.entity.GuanliyuanAdmin;
import java.sql.*;

public class GuanliyuanAdminDAO {
    private static final String URL = "jdbc:mysql://localhost:3306/course_management?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC";
    private static final String USER = "root";
    private static final String PASSWORD = "root";



    public GuanliyuanAdmin login(String username, String password) {
        String sql = "SELECT * FROM guanliyuan_admins WHERE username = ? AND password = ?";
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            try (Connection conn = DriverManager.getConnection(URL, USER, PASSWORD);
                 PreparedStatement ps = conn.prepareStatement(sql)) {
                ps.setString(1, username);
                ps.setString(2, password);
                ResultSet rs = ps.executeQuery();
                if (rs.next()) {
                    return new GuanliyuanAdmin(
                            rs.getInt("id"),
                            rs.getString("username"),
                            rs.getString("password"),
                            rs.getString("name"),
                            rs.getString("email"),
                            rs.getString("phone")
                    );
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
} 